package com.eastfair.home.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
//import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.boot.request.PageParams;
import com.eastfair.boot.service.SuperServiceImpl;
import com.eastfair.builder.ExhibitorFeign;
import com.eastfair.builder.dto.ExhibitorDTO;
import com.eastfair.builder.enumeration.ExhibitorSiteTypeEnum;
import com.eastfair.builder.vo.ExhibitorVO;
import com.eastfair.constant.BusinessConstant;
import com.eastfair.core.base.R;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.core.exception.BizException;
import com.eastfair.core.exception.NoBackBizException;
import com.eastfair.core.utils.ConvertUtil;
import com.eastfair.home.dao.ReportVenueSpaceMapper;
import com.eastfair.home.dto.ReportVenueSpaceDTO;
import com.eastfair.home.entity.ReportVenueSpace;
import com.eastfair.home.enumeration.ReportVenueSpaceDrawingAuditStatusEnum;
import com.eastfair.home.enumeration.ReportVenueSpaceReportSpaceStatusEnum;
import com.eastfair.home.exceptioncode.HomeExceptionCode;
import com.eastfair.home.service.HomeReportVenueSpaceAuditService;
import com.eastfair.home.service.ReportVenueDrawingService;
import com.eastfair.home.service.ReportVenueSpaceService;
import com.eastfair.home.service.SpaceDrawingService;
import com.eastfair.home.vo.ReportVenueSpaceVO;
import com.eastfair.venuebooking.api.ExhibitionManageFeign;
import com.eastfair.venuebooking.api.ServiceBookingFeign;
import com.eastfair.venueservice.consts.CommonConstants;
import com.eastfair.venueservice.dto.*;
import com.eastfair.venueservice.entity.CreatCode;
import com.eastfair.venueservice.enumeration.ServiceItemAuditStateEnum;
import com.eastfair.venueservice.vo.ExhibitionManageVO;
import com.eastfair.venueservice.vo.ServiceBookingVO;
import io.seata.common.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * <p>
 * 业务实现类
 * 场馆一键报馆记录
 * </p>
 *
 * @author dq
 * @date 2022-09-07
 */
@Slf4j
@Service
//@DS("#thread.tenant")
public class ReportVenueSpaceServiceImpl extends SuperServiceImpl<ReportVenueSpaceMapper, ReportVenueSpace> implements ReportVenueSpaceService {

    private static final String REPORT_VENUE_SPACE_NUMBER_PREFIX = "RSV";

    private static final String REPORT_VENUE_SPACE_NUMBER_FIELD = "report_venue_space_number";

    private static final int REPORT_VENUE_SPACE_NUMBER_LENGTH = 8;

    @Resource
    private ServiceBookingFeign serviceBookingFeign;

    @Resource
    private ReportVenueDrawingService reportVenueDrawingService;

    @Resource
    private HomeReportVenueSpaceAuditService homeReportVenueSpaceAuditService;

    @Resource
    private SpaceDrawingService spaceDrawingService;

    @Resource
    private ExhibitorFeign exhibitorFeign;

    @Resource
    private ExhibitionManageFeign exhibitionManageFeign;

    /**
     * 处理逻辑删除相关处理
     *
     * @param modelList 实体
     * @return 是否成功
     */
    @Override
    protected R<Boolean> handlerRemoveByIdsOfLogic(Collection<ReportVenueSpace> modelList) {
        modelList.forEach(s -> s.setIsDeleted(BusinessConstant.YES));
        return R.successDef();
    }

    @Override
    protected R<Boolean> handlerSave(ReportVenueSpace model) {
        model.setProjectId(ContextUtil.getProjectId());
        model.setSubsystemId(ContextUtil.getSubSystemId());

        model.setDrawingAuditStatus(ReportVenueSpaceDrawingAuditStatusEnum.NOT_SUBMIT);
        model.setReportSpaceStatus(ReportVenueSpaceReportSpaceStatusEnum.NOT_SUBMIT);
        return R.successDef();
    }

    @Override
    public IPage<ReportVenueSpaceVO> listReportVenueSpaceVOs(PageParams<ReportVenueSpaceDTO> pageParams) {
        log.info("listReportVenueSpaceVOs - 分页查询一键报馆记录VO列表, pageParams={}", pageParams);

        Page<ReportVenueSpace> paramPage = pageParams.buildPage();
        ReportVenueSpaceDTO query = pageParams.getModel();
        QueryWrapper<ReportVenueSpace> queryWrapper = createReportVenueSpaceQueryWrapper(query);
        Page<ReportVenueSpace> page = page(paramPage, queryWrapper);
        Page<ReportVenueSpaceVO> voPage = new Page<>();
        BeanUtil.copyProperties(page, voPage);

        List<ReportVenueSpace> records = page.getRecords();
        if (records == null || records.isEmpty()) {
            return voPage;
        }
        // 查询服务数量
        List<String> reportVenueSpaceNumbers = records.stream().map(ReportVenueSpace::getReportVenueSpaceNumber).collect(Collectors.toList());
        Map<String, Integer> map = serviceBookingFeign.queryBookingServiceNum(reportVenueSpaceNumbers).getData();

        List<ReportVenueSpaceVO> voList = records
                .stream()
                .map(reportVenueSpace -> {
                    ReportVenueSpaceVO reportVenueSpaceVO = BeanUtil.toBean(reportVenueSpace, ReportVenueSpaceVO.class);
                    Integer num = map.get(reportVenueSpaceVO.getReportVenueSpaceNumber());
                    reportVenueSpaceVO.setServiceNum(Objects.nonNull(num) ? num :0);
                    return reportVenueSpaceVO;
                })
                .collect(Collectors.toList());
        voPage.setRecords(voList);
        return voPage;
    }

    @Override
    public ReportVenueSpaceVO getReportVenueSpaceVOById(Long id) {
        log.info("getReportVenueSpaceVOById - 获取一键报馆记录, id={}", id);
        ReportVenueSpace reportVenueSpace = getById(id);
        if (reportVenueSpace == null) {
            return null;
        }
        return BeanUtil.toBean(reportVenueSpace, ReportVenueSpaceVO.class);
    }

    @Override
    public ReportVenueSpace getByReportVenueSpaceNumber(String reportVenueSpaceNumber) {
        QueryWrapper<ReportVenueSpace> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(ReportVenueSpace::getIsDeleted, BusinessConstant.DELETE_NO)
                .eq(StrUtil.isNotBlank(reportVenueSpaceNumber), ReportVenueSpace::getReportVenueSpaceNumber, reportVenueSpaceNumber)
        ;
        List<ReportVenueSpace> list = list(queryWrapper);
        if (list == null || list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean submitReportVenueSpace(String reportVenueSpaceNumber) {
        log.info("submitReportVenueSpace - 提交一键报馆, reportVenueSpaceNumber={}", reportVenueSpaceNumber);
        ReportVenueSpace reportVenueSpace = getByReportVenueSpaceNumber(reportVenueSpaceNumber);
        if (reportVenueSpace == null) {
            throw NoBackBizException.wrap(HomeExceptionCode.REPORT_VENUE_SPACE_NOT_EXIST);
        }
        if (ReportVenueSpaceDrawingAuditStatusEnum.APPROVED.eq(reportVenueSpace.getDrawingAuditStatus())
                || ReportVenueSpaceDrawingAuditStatusEnum.SUBMIT.eq(reportVenueSpace.getDrawingAuditStatus())) {
            throw NoBackBizException.wrap(HomeExceptionCode.REPORT_VENUE_SPACE_CAN_NOT_SUBMIT.getCode(), "一键报馆记录已提交或已审核通过，不可再提交");
        }
        // 生成一键报馆审核记录
        ReportVenueSpaceAuditDTO reportVenueSpaceAuditDTO = toReportVenueSpaceAuditDTO(reportVenueSpace);
        // 生成一键报馆报馆图纸分类审核列表
        List<ReportVenueDrawingCategoryAuditDTO> drawingAuditList = reportVenueDrawingService
                .createAuditListByReportVenueSpaceNumber(reportVenueSpace.getId(), reportVenueSpace.getReportVenueSpaceNumber());
        reportVenueSpaceAuditDTO.setReportVenueDrawingCategoryAuditList(drawingAuditList);
        // 综合服务系统生成待审核记录
        homeReportVenueSpaceAuditService.submit(reportVenueSpaceAuditDTO);
        // 更新主场一键报馆记录状态为已提交
        updateReportVenueSpaceSubmit(reportVenueSpace);
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReportVenueSpace saveReportVenueSpace(ReportVenueSpaceDTO reportVenueSpaceDTO) {
        log.info("saveReportVenueSpace - 保存一键报馆记录, reportVenueSpaceDTO={}", reportVenueSpaceDTO);
        // 生成一键报馆编码
        String reportVenueSpaceNumber = CreatCode.creatCode(baseMapper, REPORT_VENUE_SPACE_NUMBER_FIELD,
                REPORT_VENUE_SPACE_NUMBER_LENGTH, REPORT_VENUE_SPACE_NUMBER_PREFIX);
        reportVenueSpaceDTO.setReportVenueSpaceNumber(reportVenueSpaceNumber);
        // 保存一键报馆记录
        ReportVenueSpace reportVenueSpace = BeanUtil.toBean(reportVenueSpaceDTO, ReportVenueSpace.class);
        save(reportVenueSpace);
        return reportVenueSpace;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReportVenueSpace updateReportVenueSpace(ReportVenueSpaceDTO reportVenueSpaceDTO) {
        log.info("updateReportVenueSpace - 更新一键报馆记录, reportVenueSpaceDTO={}", reportVenueSpaceDTO);
        ReportVenueSpace reportVenueSpace = BeanUtil.toBean(reportVenueSpaceDTO, ReportVenueSpace.class);
        updateById(reportVenueSpace);
        return reportVenueSpace;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateReportVenueSpaceSubmit(ReportVenueSpace reportVenueSpace) {
        log.info("updateReportVenueSpaceSubmit - 更新一键报馆记录为已提交, reportVenueSpace={}", reportVenueSpace);
        reportVenueSpace.setDrawingAuditStatus(ReportVenueSpaceDrawingAuditStatusEnum.SUBMIT);
        reportVenueSpace.setDrawingAuditOpinion(null);
        reportVenueSpace.setDrawingAuditUserId(null);
        reportVenueSpace.setDrawingAuditUserName(null);
        reportVenueSpace.setReportSpaceStatus(ReportVenueSpaceReportSpaceStatusEnum.SUBMIT);
        reportVenueSpace.setLastReportTime(LocalDateTime.now());
        reportVenueSpace.setLastAuditTime(null);
        return updateAllById(reportVenueSpace);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateAuditStatus(ReportVenueSpaceDTO reportVenueSpaceDTO) {
        log.info("updateAuditStatus - 更新审核结果, reportVenueSpaceDTO={}", reportVenueSpaceDTO);
        ReportVenueSpace reportVenueSpace = getByReportVenueSpaceNumber(reportVenueSpaceDTO.getReportVenueSpaceNumber());
        if (reportVenueSpace == null) {
            throw NoBackBizException.wrap(HomeExceptionCode.REPORT_VENUE_SPACE_NOT_EXIST);
        }
        reportVenueSpace.setDrawingAuditStatus(reportVenueSpaceDTO.getDrawingAuditStatus());
        reportVenueSpace.setDrawingAuditOpinion(reportVenueSpaceDTO.getDrawingAuditOpinion());
        reportVenueSpace.setLastAuditTime(LocalDateTime.now());
        reportVenueSpace.setDrawingAuditUserId(reportVenueSpaceDTO.getDrawingAuditUserId());
        reportVenueSpace.setDrawingAuditUserName(reportVenueSpaceDTO.getDrawingAuditUserName());
        reportVenueSpace.setReportSpaceStatus(reportVenueSpaceDTO.getReportSpaceStatus());
        updateById(reportVenueSpace);
        // 审核通过，保存展馆图纸
        if (ReportVenueSpaceDrawingAuditStatusEnum.APPROVED.eq(reportVenueSpace.getDrawingAuditStatus())) {
            spaceDrawingService.saveByReportVenueSpace(reportVenueSpace);
        }
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeReportVenueSpace(List<Long> ids) {
        log.info("removeReportVenueSpace - 删除一键报馆记录, ids={}", ids);
        List<ReportVenueSpace> list = listByIds(ids);
        return removeByIdsOfLogic(list);
    }

    @Override
    public Page<ServiceBookingVO> queryServiceBookingOfHome(PageParams<ServiceBookingQuery> serviceBookingQuery) {
        Page<ServiceBookingVO> listR = ConvertUtil.convertPage(serviceBookingFeign.queryServiceBookingOfHome(serviceBookingQuery).getData(), ServiceBookingVO.class);
        // 处理报馆时间
        List<String> reportVenueSpaceNumberList = listR.getRecords().stream().map(ServiceBookingVO::getReportVenueSpaceNumber).collect(Collectors.toList());
        if (CollectionUtils.isNotEmpty(reportVenueSpaceNumberList)) {
            QueryWrapper<ReportVenueSpace> reportVenueSpaceQueryWrapper = new QueryWrapper<>();
            reportVenueSpaceQueryWrapper.lambda()
                    .eq(ReportVenueSpace::getIsDeleted, BusinessConstant.NO)
                    .in(ReportVenueSpace::getReportVenueSpaceNumber, reportVenueSpaceNumberList);
            Map<String, ReportVenueSpace> collect = list(reportVenueSpaceQueryWrapper).stream().collect(Collectors.toMap(ReportVenueSpace::getReportVenueSpaceNumber, Function.identity()));
            for (ServiceBookingVO record : listR.getRecords()) {
                String reportVenueSpaceNumber = record.getReportVenueSpaceNumber();
                ReportVenueSpace reportVenueSpace = collect.get(reportVenueSpaceNumber);
                if (Objects.nonNull(reportVenueSpace)) {
                    record.setLastReportTime(reportVenueSpace.getLastReportTime());
                }
            }
        }
        return listR;
    }

    /**
     * ReportVenueSpace 转为 ReportVenueSpaceAuditDTO.
     *
     * @param reportVenueSpace reportVenueSpace
     * @return reportVenueSpaceAuditDTO
     */
    private ReportVenueSpaceAuditDTO toReportVenueSpaceAuditDTO(ReportVenueSpace reportVenueSpace) {
        List<String> ignoreProperties = new ArrayList<>();
        Collections.addAll(ignoreProperties, CommonConstants.COMMON_IGNORE_PROPERTIES);
        Collections.addAll(ignoreProperties, "reportSpaceStatus", "drawingAuditStatus", "drawingAuditOpinion",
                "drawingAuditUserId", "drawingAuditUserName", "lastReportTime", "lastAuditTime");
        String[] ignoreArray = new String[ignoreProperties.size()];
        ignoreProperties.toArray(ignoreArray);
        CopyOptions copyOptions = CopyOptions
                .create()
                .setIgnoreProperties(ignoreArray);
        ReportVenueSpaceAuditDTO reportVenueSpaceAuditDTO = BeanUtil.toBean(reportVenueSpace, ReportVenueSpaceAuditDTO.class, copyOptions);
        reportVenueSpaceAuditDTO.setReportVenueSpaceId(reportVenueSpace.getId());
        return reportVenueSpaceAuditDTO;
    }

    @Override
    public Boolean submitServiceBookingToVenue(List<ServiceBookingDTO> serviceBookingDTO) {
        R<Boolean> booleanR = serviceBookingFeign.submitServiceBookingToVenue(serviceBookingDTO);
        if (!booleanR.getIsSuccess()) {
            throw new BizException(booleanR.getCode(), booleanR.getMsg());
        }
        return booleanR.getData();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void checkImport(MultipartFile file, Long exhibitionManageId, Long homeId, String spaceName) throws Exception {
        if (file == null) {
            throw BizException.wrap(-1, "未上传文件");
        }
        InputStream inputStream = file.getInputStream();
        ExcelReader reader = ExcelUtil.getReader(inputStream);
        List<Map<String, Object>> importList = reader.readAll();
        if (importList == null || importList.isEmpty()) {
            throw BizException.wrap(-1, "读取数据为空");
        }
        // 校验展位-展商-搭建商关系
        ExhibitorDTO queryDTO = new ExhibitorDTO();
        queryDTO.setExhibitionManageId(exhibitionManageId);
        ExhibitionManageQuery exhibitionManageQuery = new ExhibitionManageQuery();
        exhibitionManageQuery.setId(exhibitionManageId);
        R<ExhibitionManageVO> exhibitionManageVOR = exhibitionManageFeign.queryExhibitionManageDetail(exhibitionManageQuery);
        R<List<ExhibitorVO>> listR = exhibitorFeign.queryExhibitors(queryDTO);
        Set<String> checkExhibitorSet = listR.getData().stream().map(e -> e.getSiteName() + BusinessConstant.COMMA + e.getBuilderName() + BusinessConstant.COMMA + e.getExhibitorName()).collect(Collectors.toSet());
        Set<String> checkSiteSet = listR.getData().stream().map(ExhibitorVO::getSiteName).collect(Collectors.toSet());
        Map<String, ExhibitorDTO> exhibitionList = new HashMap<>(8);
        List<ServiceBookingDTO> serviceBookingList = new ArrayList<>(16);
        for (int i = 0; i < importList.size(); i ++) {
            int rowIndex = i + 2;
            Map<String, Object> map = importList.get(i);
            // 封装报馆对象
            ServiceBookingDTO serviceBooking = new ServiceBookingDTO();
            ExhibitorDTO exhibitorDTO = new ExhibitorDTO();
            serviceBooking.setExhibitionManageId(exhibitionManageId);
            serviceBooking.setAuditState(ServiceItemAuditStateEnum.APPROVED.getCode());
            exhibitorDTO.setExhibitionManageId(exhibitionManageId);
            exhibitorDTO.setExhibitionManageName(exhibitionManageVOR.getData().getExhibitionName());
            serviceBooking.setHomeId(homeId);
            map.forEach((k,v)->{
                if(Objects.isNull(v) || StringUtils.isBlank(v.toString())){
                    throw BizException.wrap(-1, "第" + rowIndex + "行，" + k + "为空");
                }else {
                    dealVO(spaceName, rowIndex, serviceBooking, exhibitorDTO, k, v);
                }
            });
            String key =exhibitorDTO.getSiteName() + BusinessConstant.COMMA + exhibitorDTO.getBuilderName() + BusinessConstant.COMMA + exhibitorDTO.getExhibitorName();
            serviceBookingList.add(serviceBooking);
            // 展位存在，关系不匹配
            if(checkSiteSet.contains(exhibitorDTO.getSiteCode()) && !checkExhibitorSet.contains(exhibitorDTO.getSiteName() + BusinessConstant.COMMA + exhibitorDTO.getBuilderName() + BusinessConstant.COMMA + exhibitorDTO.getExhibitorName())){
                throw BizException.wrap(-1, exhibitorDTO.getSiteName() + "-" + exhibitorDTO.getBuilderName() + "-"  + exhibitorDTO.getExhibitorName()+" 与系统存在的展位-搭建商-展商关系不匹配，请检查后重试！");
            } else if (!checkExhibitorSet.contains(exhibitorDTO.getSiteName() + BusinessConstant.COMMA + exhibitorDTO.getBuilderName() + BusinessConstant.COMMA + exhibitorDTO.getExhibitorName())) {
                exhibitionList.put(key,exhibitorDTO);
            }
        }
        // 绑定展商
        exhibitorFeign.saveExhibitorOnlyExhibitor(new ArrayList<>(exhibitionList.values()));
        // 插入报馆明细
        serviceBookingFeign.submitServiceBookingToVenueOfImport(serviceBookingList);
    }

    private void dealVO(String spaceName, int rowIndex, ServiceBookingDTO serviceBooking, ExhibitorDTO exhibitorDTO, String k, Object v) {
        switch (k){
            case "展厅号":
                if(spaceName.equals(v.toString().trim())){
                    serviceBooking.setSpaceName(v.toString().trim());
                    exhibitorDTO.setSpaceName(v.toString().trim());
                }else {
                    throw BizException.wrap(-1, "第" + rowIndex + "行，" + k + "值有误");
                }
                break;
            case "展位号":
                serviceBooking.setSiteName(v.toString().trim());
                exhibitorDTO.setSiteName(v.toString().trim());
                break;
            case "展位类型（1特装、2标摊）":
                if (Integer.parseInt(v.toString().trim()) == 1) {
                    exhibitorDTO.setSiteType(ExhibitorSiteTypeEnum.SPECIAL);
                } else if (Integer.parseInt(v.toString().trim()) == 2) {
                    exhibitorDTO.setSiteType(ExhibitorSiteTypeEnum.STANDARD);
                }
                break;
            case "展位面积":
                exhibitorDTO.setSiteArea(BigDecimal.valueOf(Double.parseDouble(v.toString().trim())));
                break;
            case "参展商名称":
                serviceBooking.setExhibitorName(v.toString().trim());
                exhibitorDTO.setExhibitorName(v.toString().trim());
                break;
            case "参展商联系人":
                exhibitorDTO.setExhibitorContacts(v.toString().trim());
                break;
            case "参展商联系方式":
                exhibitorDTO.setExhibitorContactsTel(v.toString().trim());
                break;
            case "搭建商名称":
                serviceBooking.setBusinessName(v.toString().trim());
                exhibitorDTO.setBuilderName(v.toString().trim());
                break;
            case "搭建商联系人":
                exhibitorDTO.setContact(v.toString().trim());
                break;
            case "搭建商联系方式":
                exhibitorDTO.setContactMobile(v.toString().trim());
                break;
//                        case "搭建商社会统一信用代码":
//                            break;
            case "服务项ID":
                serviceBooking.setServiceItemId(Long.parseLong(v.toString().trim()));
                break;
            case "分类ID":
                serviceBooking.setServiceCategoryId(Long.parseLong(v.toString().trim()));
                break;
            case "规格ID":
                serviceBooking.setServiceSpecsId(Long.parseLong(v.toString().trim()));
                break;
            case "数量":
                serviceBooking.setBookingNum(Long.parseLong(v.toString().trim()));
                break;
            default:
                break;
        }
    }

    /**
     * 生成ReportVenueSpace的查询
     *
     * @param query ReportVenueSpaceDTO.
     * @return ReportVenueSpace.
     */
    private QueryWrapper<ReportVenueSpace> createReportVenueSpaceQueryWrapper(ReportVenueSpaceDTO query) {
        QueryWrapper<ReportVenueSpace> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .lambda()
                .eq(ReportVenueSpace::getIsDeleted, BusinessConstant.DELETE_NO)
                .like(StrUtil.isNotBlank(query.getReportVenueSpaceNumber()), ReportVenueSpace::getReportVenueSpaceNumber, query.getReportVenueSpaceNumber())
                .like(StrUtil.isNotBlank(query.getSpaceName()), ReportVenueSpace::getSpaceName, query.getSpaceName())
                .eq(query.getId() != null, ReportVenueSpace::getId, query.getId())
                .eq(query.getExhibitionId() != null, ReportVenueSpace::getExhibitionId, query.getExhibitionId())
                .eq(query.getHomeCourtId() != null, ReportVenueSpace::getHomeCourtId, query.getHomeCourtId())
        ;
        return queryWrapper;
    }
}
